<?php
include('../function/config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel=StyleSheet HREF="../stylesheet/stylesheet.css" TYPE="text/css" MEDIA=screen>
<title><?php echo $config['title'];?></title>
<link rel="shortcut icon" href="../image/Letter-T.ico" />
<style type="text/css">
body {
	background-color: #E6F2FF;
	margin: 20px auto;
	padding: 0;
	height: 100%;
	width: 900px;
}

.content{
	background-color: #ffffff;
}

</style>
<script>
function setFocus(){
document.formsearch.name_search.focus();
}
</script>
</head>
<body onload="setFocus();">
<?php
include("../connect/connect.php");
include("../function/thaidate.php");

//ค้นหาข้อมูล
if($_POST["name_search"] != "" OR $_POST["phone_search"] != "") {
	
		$Query = "SELECT * FROM debtor_total WHERE debtortype_id = '2' AND debtor_total_status = '0' ";

	if($_POST["name_search"] != "") {
		$Query .= "AND debtor_total_name LIKE '%".$_POST["name_search"]."%' ";
	}
	
	if($_POST["phone_search"] != "") {
		$Query .= "AND debtor_total_phone LIKE '%".$_POST["phone_search"]."%' ";
	}
	
} else {
	$Query = "SELECT * FROM debtor_total WHERE debtortype_id = '2' AND debtor_total_status = '0'";
}
$objQuery = mysql_query($Query) or die ("Error Query [".$Query."]");
?>
<br /><br />
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>รับชำระหนี้</h1>
    <div class="buttons"><a onclick="location = '../sale/index.php';" class="button"><span>ยกเลิก</span></a></div></div>
  <div class="content">
  <table class="list">
        <thead>
          <tr>
            <td width="1" style="text-align: center;"><span class="center">ลำดับ</span></td>
            <td class="center">ชื่อ-นามสกุล</td>
            <td class="center">เบอร์โทรศัพท์</td>
            <td class="center">วันที่ค้างชำระ</td>
            <td class="center">ยอดเงิน</td>
            <td class="center">จัดการ</td>
          </tr>
        </thead>
        <tbody>
		<form action="<?php $_SERVER["PHP_SELF"];?>" name="formsearch" method="post" id="formsearch">
          <tr class="filter">
            <td>&nbsp;</td>
            <td align="center"><input name="name_search" type="text" id="name_search" style="text-align: center;" onkeydown="if(event.keyCode==13){formsearch.submit();}" /></td>
            <td align="center"><input name="phone_search" type="text" id="phone_search" style="text-align: center;" onkeydown="if(event.keyCode==13){formsearch.submit();}" /></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="center"><a onclick="formsearch.submit();" class="button"><span>ค้นหา</span></a></td>
          </tr>
		</form>
<?php
	$num = 0;
	while($row = mysql_fetch_array($objQuery))
		{
			$num++;
?>
          <tr>
            <td style="text-align: center;"><?php echo $num;?></td>
            <td class="left" style="padding-left:20px"><?php echo $row["debtor_total_name"];?></td>
            <td class="center"><?php if($row["debtor_total_phone"]==""){ echo "-"; } else { echo $row["debtor_total_phone"]; }?></td>
            <td class="right" style="padding-right:20px"><?php echo thai_date($row['debtor_total_date']); ?></td>
            <td class="right" style="padding-right:20px"><?php echo "".number_format($row['debtor_total_total'], 2,'.',',');?></td>
            <td class="center">[ <a href="debtor_payment.php?id=<?php echo $row["debtor_total_id"];?>">รับชำระหนี้</a> ]</td>
          </tr>
<?php
		}
?>
        </tbody>
      </table>
  </div>
</div>

</body>
<? mysql_close(); ?>
</html>
